package com.hds.modules.sys.controller.base;

import com.hds.common.annotation.SysLog;
import com.hds.common.utils.PageUtils;
import com.hds.common.utils.R;
import com.hds.common.validator.ValidatorUtils;
import com.hds.modules.sys.entity.base.SysMemberShipEntity;
import com.hds.modules.sys.service.base.SysMemberShipService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 会员
 *
 * @Author guonan
 * @Email guonan@yewcn.com
 * @Description
 * @Date 2018/6/12 14:16
 */
@RestController
@RequestMapping("/sys/membership")
public class SysMemberShipController {

    @Autowired
    private SysMemberShipService sysMemberShipService;

    @SysLog("保存会员")
    @PostMapping("/saveOrUpdate")
    public R saveOrUpdate(@RequestBody SysMemberShipEntity memberShip){
        ValidatorUtils.validateEntity(memberShip);
        boolean rst = false;
        Integer id = memberShip.getId();
        rst = (id!=null) ?
                sysMemberShipService.update(memberShip) :
                sysMemberShipService.save(memberShip);

       return rst ? R.ok() : R.error();
    }

    @SysLog("会员列表")
    @GetMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = sysMemberShipService.queryPage(params);

        return R.ok().put("page", page);
    }





}
